package com.twohand.admin.Util;

import com.twohand.admin.Vo.ExpiredTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.*;

public class WxOrderUtil {
    public static Logger log = LoggerFactory.getLogger(WxOrderUtil.class);
    public static String genWxOrderNo(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String numbers = WxOrderUtil.genRandomNumber(4);
//        String uuid = UUID.randomUUID().toString().replaceAll("-","");
//        log.info("生成新的订单号:"+uuid);
        String no = sdf.format(new Date()) + numbers;
        log.info("生成新的订单号:"+no);
        return no;
    }
    public static String genWxRefundNo(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String numbers = WxOrderUtil.genRandomNumber(4);
        String no = "rf" + sdf.format(new Date()) + numbers;
        log.info("生成新的订单号:"+no);
        return no;
    }
    public static String genRandomNumber(Integer n){
        List<String> randomNumbers = new ArrayList<>();
        Random random = new Random();
        while (randomNumbers.size() < n){
            String randomNum = String.valueOf(random.nextInt(10));
            if(!randomNumbers.contains(randomNum)){
                randomNumbers.add(randomNum);
            }
        }
        return String.join("",randomNumbers);
    }
    public static ExpiredTime getTime(){
        ExpiredTime expired = new ExpiredTime();
        Date startDate = new Date();
        Long expiredTime = startDate.getTime() + 2 * 60 * 60 * 1000;
        Date expiredDate = new Date();
        expiredDate.setTime(expiredTime);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdfRcf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
        expired.setExpiredTime(sdf.format(expiredDate));
        expired.setExpiredTimeRfc(sdfRcf.format(expiredDate));
        return expired;
    }
}
